package ee.siimkaspar.subjects.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Entity
@Table(name = "subject_type")
public class SubjectType implements Serializable, ModelInterface {

	@Id
	@Column(name = "subject_type", unique = true, nullable = false)
	private Integer id;
	@Column(name = "type_name", length = 200)
	private String typeName;
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<Contact> contacts = new ArrayList<Contact>();
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<SubjectAttributeType> subjectAttributeTypes = new ArrayList<SubjectAttributeType>();
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<UserAccount> userAccounts = new ArrayList<UserAccount>();
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<SubjectAttribute> subjectAttributes = new ArrayList<SubjectAttribute>();
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<Customer> customers = new ArrayList<Customer>();
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectType")
	private List<Address> addresses = new ArrayList<Address>();

	public SubjectType() {
	}
	
	public SubjectType(String typeName) {
		this.typeName = typeName;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTypeName() {
		return this.typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public List<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(List<Contact> contacts) {
		this.contacts = contacts;
	}

	public List<SubjectAttributeType> getSubjectAttributeTypes() {
		return subjectAttributeTypes;
	}

	public void setSubjectAttributeTypes(
			List<SubjectAttributeType> subjectAttributeTypes) {
		this.subjectAttributeTypes = subjectAttributeTypes;
	}

	public List<UserAccount> getUserAccounts() {
		return userAccounts;
	}

	public void setUserAccounts(List<UserAccount> userAccounts) {
		this.userAccounts = userAccounts;
	}

	public List<SubjectAttribute> getSubjectAttributes() {
		return subjectAttributes;
	}

	public void setSubjectAttributes(List<SubjectAttribute> subjectAttributes) {
		this.subjectAttributes = subjectAttributes;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public List<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(List<Address> addresses) {
		this.addresses = addresses;
	}
	
	@Override
	public String toString() {
		return typeName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((typeName == null) ? 0 : typeName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SubjectType other = (SubjectType) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (typeName == null) {
			if (other.typeName != null)
				return false;
		} else if (!typeName.equals(other.typeName))
			return false;
		return true;
	}
	@Override
	public boolean validate() {
		// TODO Auto-generated method stub
		return true;
	}
	
}
